package com.by.controller;


import com.by.constant.MessageConstant;
import com.by.entity.Result;
import com.by.pojo.OrderSetting;
import com.by.service.OrderSettingService;
import com.by.util.POIUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@RestController
@RequestMapping("/ordersetting")
public class OrderSettingController {

    @Autowired
    private OrderSettingService orderSettingService;

    /**
     * @Description: 导入预约设置信息
     * @Param: * @param excelFile
     * @return: com.by.entity.Result
     * @Author: GP
     * @Date: 2024/1/12
     */
    @RequestMapping("/upload")
    public Result upload(MultipartFile excelFile) {
        try {
            List<String[]> stringList = POIUtils.readExcel(excelFile);
            orderSettingService.addOrderSetting(stringList);
            return new Result(true, MessageConstant.IMPORT_ORDERSETTING_SUCCESS);
        } catch (IOException e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.IMPORT_ORDERSETTING_FAIL);
        }
    }

    /**
     * @Description: 根据日期查询预约设置信息
     * @Param: * @param date
     * @return: com.by.entity.Result
     * @Author: GP
     * @Date: 2024/1/12
     */
    @RequestMapping("/getOrderSettingByMonth")
    public Result getOrderSettingByMonth(String date) {
        try {
            List<Map<String, Object>> mapList = orderSettingService.getOrderSettingByMonth(date);
            return new Result(true, MessageConstant.GET_BUSINESS_REPORT_SUCCESS, mapList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.GET_ORDERSETTING_FAIL);
        }
    }


    /**
    * @Description: 基于日历设置预约人数
            * @Param: * @param orderSetting
            * @return: com.by.entity.Result
            * @Author: GP
            * @Date: 2024/1/12
            */
    @RequestMapping("/editNumberByDate")
    public Result editNumberByDate(@RequestBody OrderSetting orderSetting) {
        try {
            orderSettingService.editNumberByDate(orderSetting);
            return new Result(true, MessageConstant.ORDERSETTING_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.ORDERSETTING_FAIL);
        }
    }
}
